package com.ryan.spring.annotation.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * Created by kaimin on 26/1/2019.
 * time : 23:00
 * 判断匹配Linux的
 */
public class LinuxConditional implements Condition {
    /**
     *
     * @param context 使用的上下文，即环境
     * @param metadata 当前标注condition注解的 注解信息
     * @return
     */
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //判断是否Linux系统
        //能获取bean工厂
//        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
//        context.getClassLoader();//获取类加载器
        Environment environment = context.getEnvironment();//获取当前环境变量
//        context.getRegistry();//能获取到定义的注册类
        String osName = environment.getProperty("os.name");
        if (osName.equalsIgnoreCase("Mac OS X")) {
            return true;
        }else
            return false;
    }
}
